package com.cn.server.handler.mobile;

import com.cn.common.core.exception.ErrorResponse;
import com.cn.common.core.model.Request;
import com.cn.common.core.model.Result;
import com.cn.common.core.model.ResultCode;
import com.cn.common.core.session.Session;
import com.cn.server.msg.MessageHandler;
import com.cn.server.Constant;
import com.cn.server.module.chat.handler.ChatHandler;
import com.cn.server.module.chat.handler.ChatHandlerImpl;
import com.cn.server.module.login.ImUser;

public class SingleChatHandler implements MessageHandler {
    private ChatHandler chatHandler = new ChatHandlerImpl();

    @Override
    public Result<?> handle(Request packet, Session session) {
        Object attachment = session.getAttachment();
        if (attachment != null) {
            ImUser imUser = (ImUser) attachment;
            return chatHandler.privateChat(imUser.getLoginName(), packet.getData());
        } else {
            return Result.ERROR(new ErrorResponse(ResultCode.LOGIN_PLEASE, Constant.UN_LOGIN_ERROR));
        }
    }
}
